package com.filestation.backend.repository;

import com.filestation.backend.entity.FileInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@Repository
public interface FileInfoRepository extends JpaRepository<FileInfo, Long> {

    Optional<FileInfo> findByFileKeyAndIsDeletedFalse(String fileKey);

    Optional<FileInfo> findByDownloadCodeAndIsDeletedFalse(String downloadCode);

    @Query("SELECT f FROM FileInfo f WHERE f.expirationTime < ?1 AND f.isDeleted = false")
    List<FileInfo> findExpiredFiles(Date now);

    List<FileInfo> findByIsDeletedFalseOrderByUploadTimeDesc();
} 